package cn.nnxy.system.controller;

import cn.nnxy.system.domain.Student;
import cn.nnxy.system.mapper.StudentMapper;
import cn.nnxy.system.query.StudentQuery;
import cn.nnxy.system.service.StudentService;
import cn.nnxy.system.utils.DataUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
*学籍管理控制器
*@author chenliming
*@data 2021-5-29 18:41
 *@return {@link }
*@throws
*/
@Controller
@RequestMapping("/management")
public class StudentController {


    @Autowired
    private StudentService studentService;

   /**
   *跳转学生学籍列表
   *@author chenliming
   */
    @GetMapping("studentList")
    public String listUI() {
        return "studentList";
    }

    @ResponseBody
    @GetMapping("listData")
    public Map<String,Object> archive(StudentQuery query){
        Integer pageSize = 10;
        query.setPageSize(pageSize);
        PageHelper.startPage(query.getCurPage(), query.getPageSize());
        List<Student> studentlist = studentService.queryList();
        PageInfo<Student> pageInfo = new PageInfo<>(studentlist);
        Map<String, Object> dataMap = DataUtil.convertToJsonMap(studentlist, pageInfo.getTotal());
        return dataMap;
    }
    /**
    *新增学生学籍档案
    *@author chenliming
     * @PostMapping("add")
     *     public String add(@Validated Manager manager, Model model, BindingResult result) {
     *         if (result.hasErrors()) {
     *             model.addAttribute("manager", manager);
     *             model.addAttribute("msg", result.getAllErrors());
     *             return "manager/add";
     *         }
     *         int num = managerService.saveManager(manager);
     *         if (num == 1) {
     *             model.addAttribute("msg", "添加成功！");
     *             return "redirect:/back/manager/list";
     *         } else {
     *             model.addAttribute("msg", "添加失败！");
     *             return "manager/add";
     *         }
     *
     *     }
    */



}
